//
// File:	Window.cpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Create:	28/01/2010 at 17:37:36
// Purpose:	
//
#include <QtGui/QApplication>
#include <QtGui/QVBoxLayout>
#include "Window.hpp"
#include "Trace.hpp"

//------------------------------------------------------------------
// Constructor / Destructor
//------------------------------------------------------------------
Window::Window(const std::string &windowTitle /* = "" */, int iWidth /* = 0 */, int iHeight /* = 0 */, bool bFullScreen /* = false */)
	:	QWidget(NULL)
{
	//Window Settings
	SetWindowTitle(windowTitle);
	SetWindowSize(iWidth, iHeight);
	SetFullScreen(bFullScreen);

	//Create a layout
	QVBoxLayout *pLayout = new QVBoxLayout(this);
	pLayout->setMargin(0);
}

Window::~Window()
{
}

//------------------------------------------------------------------
// Window Settings
//------------------------------------------------------------------
void Window::SetWindowTitle(const std::string &windowTitle)
{
	setWindowTitle(QString::fromStdString(windowTitle));
}

void Window::SetWindowSize(int iWidth, int iHeight)
{
	m_iWidth = iWidth;
	m_iHeight = iHeight;
	resize(iWidth, iHeight);
}

void Window::SetFullScreen(bool bFullScreen)
{
	if (bFullScreen)
	{
		showFullScreen();
		return;
	}
	if (isMaximized())
	{
		showMaximized();
		return;
	}
	showNormal();
}

//------------------------------------------------------------------
// Render
//------------------------------------------------------------------
bool Window::Render()
{
	//UNDONE
	//...
	return true;
}

//------------------------------------------------------------------
// Close
//------------------------------------------------------------------
void Window::closeEvent(QCloseEvent *e)
{
	emit closed();
	QWidget::closeEvent(e);
}

//------------------------------------------------------------------
// Accessors and mutators
//------------------------------------------------------------------
int Window::GetWidth() const
{
	return m_iWidth;
}

int Window::GetHeight() const
{
	return m_iHeight;
}

int Window::GetReferenceWidth() const
{
	return 640;
}

int Window::GetReferenceHeight() const
{
	return 480;
}
